package com.tongji.housediy.view.titlewindows
{
	import com.tongji.housediy.model.ExchangeDataModel;
	import com.tongji.housediy.model.SelectedObjectModel;
	import com.tongji.housediy.view.components.AbstractDrawingRoom;
	import com.tongji.housediy.view.components.InfoLine;
	import com.tongji.housediy.view.components.SpecificRoom;
	
	import flash.display.BlendMode;
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	import mx.collections.ArrayCollection;
	import mx.managers.PopUpManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	import spark.filters.GlowFilter;
	
	public class RoomInfoWindowMediator extends Mediator
	{
		[Inject]
		public var view:RoomInfoTitleWindow;
		
		[Inject]
		public var selectedModel:SelectedObjectModel;
		
		[Inject]
		public var exchangeModel:ExchangeDataModel;
		
		override public function onRegister():void
		{
			view.heightTextInput.text = (selectedModel.selectedObj.parent as AbstractDrawingRoom).roomHeight.toString();
			view.nameTextInput.text = (selectedModel.selectedObj.parent as AbstractDrawingRoom).roomName;
			
			view.closeBtn.addEventListener(MouseEvent.CLICK, closeWindowHandler);
			view.cancelBtn.addEventListener(MouseEvent.CLICK, closeWindowHandler);
			view.okBtn.addEventListener(MouseEvent.CLICK, okBtnClickHandler);
			view.checkBox.addEventListener(MouseEvent.CLICK, checkBoxClickHandler);
			view.checkBox1.addEventListener(MouseEvent.CLICK, checkBox1ClickHandler);
		}
		private function checkBoxClickHandler(event:MouseEvent):void
		{
			if(view.checkBox.selected == true)
				view.checkBox.selected == false;
			else
				view.checkBox.selected == true;
		}
		private function checkBox1ClickHandler(event:MouseEvent):void
		{
			if(view.checkBox1.selected == true)
				view.checkBox1.selected == false;
			else
				view.checkBox1.selected == true;
		}
		private function closeWindowHandler(event:MouseEvent):void
		{
			PopUpManager.removePopUp(view);
			mediatorMap.removeMediatorByView(view);
		}
		
		private function okBtnClickHandler(event:MouseEvent):void//带求证其正确性
		{
			if (view.checkBox1.selected)
			{
				//exchangeModel.gridContainer.setChildRoomInfo(int(view.heightTextInput.text));
				(selectedModel.selectedObj.parent as AbstractDrawingRoom).roomHeight = int(view.heightTextInput.text);
			}
			if (view.checkBox.selected)
			{
				exchangeModel.gridContainer.setChildRoomInfo(int(view.heightTextInput.text));
				/*var i:int = 0;
				while((selectedModel.selectedObj.parent.parent.getChildAt(i) is SpecificRoom) )
				{
					(selectedModel.selectedObj.parent.parent.getChildAt(i) as AbstractDrawingRoom).roomHeight = int(view.heightTextInput.text);
					i++;
				}*/
			}
			(selectedModel.selectedObj.parent as AbstractDrawingRoom).roomName = view.nameTextInput.text;
			
			closeWindowHandler(event);
		}
		
	}
}